<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * This is a placeholder class.
 * Create the same file in app/app_controller.php
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 * @link http://book.cakephp.org/view/957/The-App-Controller
 */
class AppController extends Controller {
    
    var $components = array('RequestHandler', 
                            'Session', 
                            'Auth' => array(
                                'authorize' => 'controller',
                                'allowedActions' => array('display'),
                                'logoutRedirect' => array('controller' => 'pages', 'action' => 'home')
                            ));
    
    var $helpers = array('Javascript', 'Session');
    
    function get_districts_list() {
        
        $this->autoRender = false;  // non renderizza la view

        if($this->RequestHandler->isAjax()) {
            $options = array(
                        'fields' => array('id', 'name'),
                        'conditions' => "region_id = '{$this->params['form']['region_id']}'");
            echo json_encode($this->District->find('list', $options));
        }
        
    }
    
    function get_towns_list() {
        
        $this->autoRender = false;  // non renderizza la view

        if($this->RequestHandler->isAjax()) {
            $options = array(
                        'fields' => array('id', 'name'),
                        'conditions' => "district_id = '{$this->params['form']['district_id']}'");
            echo json_encode($this->Town->find('list', $options));
        }
        
    }
    
    
}
